package com.boyu.backend;

import com.boyu.common.BaseController;
import com.boyu.common.showmodel.ShowMenu;
import com.boyu.common.MenuLogic;
import com.boyu.common.SystemConst;
import com.boyu.common.model.Menu;

import java.util.List;

/**
 * IndexController
 */
public class _MenuController extends BaseController {

    public void index() {
        List<ShowMenu> menus = MenuLogic.getInstance().menuLoad();
        setSessionAttr(SystemConst.ADMIN_MENU, menus);
        render(INDEX_HTML);
    }

    public void add() {
        int parentId = getParaToInt(PARENT_ID, -1);
        setAttr(PARENT_ID, parentId);
        render(ADD_HTML);
    }

    public void edit() {
        Menu byId = Menu.dao.findById(getParId());
        setAttr(MENU, byId);
        render(EDIT_HTML);
    }

    public void del() {
        Menu.dao.deleteById(getParId());
        redirect(INDEX);
    }

    public void save() {
        Menu model = getModel(Menu.class, "");
        if (model.getId() != null) {
            model.update();
        } else {
            model.save();
        }
        redirect(INDEX);
    }
}





